package top.liuziqian.web.controller.shop.goods;




import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.liuziqian.common.annotation.Log;
import top.liuziqian.common.core.controller.BaseController;
import top.liuziqian.common.core.domain.AjaxResult;
import top.liuziqian.common.core.page.TableDataInfo;
import top.liuziqian.common.enums.BusinessType;
import top.liuziqian.shop.domain.GoodsSupplierCategory;
import top.liuziqian.shop.service.IGoodsSupplierCategoryService;
import top.liuziqian.shop.service.IGoodsSupplierCategoryService;

import java.util.List;


@Controller
@RequestMapping("/goods/supplier/category")
@Api("商品供应商分类管理")
public class SupplierCategoryController extends BaseController {

    private String prefix = "shop/goods/supplier/category";

    @Autowired
    private IGoodsSupplierCategoryService goodsSupplierCategoryService;

    @RequiresPermissions("goods:supplier:category:view")

    @GetMapping()
    public String category()
    {
        return prefix + "/category";
    }


    /**
     * 新增供应商分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @GetMapping("/edit/{supplierCategoryId}")
    public String edit(@PathVariable("supplierCategoryId") Long supplierCategoryId, ModelMap mmap)
    {
        mmap.put("goodsSupplierCategory",goodsSupplierCategoryService.selectSupplierCategoryById(supplierCategoryId));
        return prefix + "/edit";
    }

    /**
     * 查询供应商分类列表
     */
    @RequiresPermissions("goods:supplier:category:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("获取商品供应商分类")
    public TableDataInfo list(GoodsSupplierCategory goodsSupplierCategory)
    {
        startPage();
        List<GoodsSupplierCategory> list = goodsSupplierCategoryService.selectSupplierCategoryList(goodsSupplierCategory);
        return getDataTable(list);
    }


    /**
     * 新增供应商分类
     */
    @RequiresPermissions("goods:supplier:category:add")
    @Log(title = "商品供应商分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated GoodsSupplierCategory goodsSupplierCategory)
    {
        goodsSupplierCategory.setCreateBy(getLoginName());
        return toAjax(goodsSupplierCategoryService.insertSupplierCategory(goodsSupplierCategory));
    }

    @RequiresPermissions("goods:supplier:category:edit")
    @Log(title = "商品供应商分类", businessType = BusinessType.INSERT)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated GoodsSupplierCategory goodsSupplierCategory)
    {
        goodsSupplierCategory.setUpdateBy(getLoginName());
        return toAjax(goodsSupplierCategoryService.updateSupplierCategory(goodsSupplierCategory));
    }

    /**
     * 删除供应商分类
     */
    @RequiresPermissions("goods:supplier:category:remove")
    @Log(title = "供应商分类", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(goodsSupplierCategoryService.deleteSupplierCategoryByIds(ids));
    }
}

